{extend name="template/base" /}
{block name="content"}
<div class="page-container">
    {include file="form" /}
    <div class="cl pd-5 bg-1 bk-gray">
        <span class="l">
            <a class="btn btn-primary radius" id="batch_settlement" href="javascript:;" onclick="layer.prompt({title: '结算方式', formType: 2},batch_settlement)">批量结算</a>
            <a class="btn btn-primary radius" id="batch_refuse" href="javascript:;" onclick="layer.prompt({title: '驳回原因', formType: 2},batch_refuse)">批量驳回</a>
            <a class="btn btn-primary radius mr-5" id="sou" href="{:url('/admin/driver_settlement/get_excel',$searchCondition)}" >excel导出</a>
            <a class="btn btn-primary radius mr-5" id="xuan" style="display: none;"  href="javascript:;" onclick="xuan()">excel导出</a>
        </span>
        <span class="r pt-5 pr-5">
            共有数据 ：<strong>{$count ?? '0'}</strong> 条
        </span>
    </div>
    <table class="table table-border table-bordered table-hover table-bg mt-20">
        <thead>
        <tr class="text-c">
            {include file="th" /}
            <th width="70">操作</th>
        </tr>
        </thead>
        <tbody>
        {volist name="$list" id="vo"}
        <tr class="text-c">
            {include file="td" /}
            <td class="f-14">
                <a title="允许结算" href="javascript:;" onclick="layer_open('允许结算','/admin/dispatch_traveler_group/confirm_settlement/group_id/{$vo.id}')" style="text-decoration:none" class="ml-5 label label-success radius">允许结算</a>
                <a title="驳回结算" href="javascript:;" onclick="layer_open('驳回结算','/admin/dispatch_traveler_group/refuse_settlement/group_id/{$vo.id}')" style="text-decoration:none" class="ml-5 label label-warning radius">驳回结算</a>
            </td>
        </tr>
        {/volist}
        </tbody>
    </table>
    <div class="page-bootstrap">{$page ?? ''}</div>
</div>
<script type="text/javascript" src="__LIB__/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript">

</script>

<script>
    // 批量结算
    function batch_settlement(pass, index){
        var checkData = $("input:checked[name='id[]']");
        var dataArr = checkData.serializeArray();
        $.ajax({
            type: 'POST',
            url: "/admin/dispatch_traveler_group/batch_settlement?settlement_mode=" + pass,
            data: dataArr,
            success: function (re) {
                if (re.msg) {
                    layer.alert(re.msg, function(index){
                        //关闭后刷新
                        location.reload();
                    });
                }
            }
        });
    }

    // 批量驳回
    function batch_refuse(pass, index){
        var checkData = $("input:checked[name='id[]']");
        var dataArr = checkData.serializeArray();
        $.ajax({
            type: 'POST',
            url: "/admin/dispatch_traveler_group/batch_refuse?reject_settlement_reason=" + pass,
            data: dataArr,
            success: function (re) {
                if (re.msg) {
                    layer.alert(re.msg, function(index){
                        //关闭后刷新
                        location.reload();
                    });
                }
            }
        });
    }

    //全选
    $('#checkAlls').bind("click", function () {
        $("input[name='id[]']").prop("checked",this.checked);
        var sonChecked = $("input[name='id[]']").prop('checked');
        var allChecked = this.checked
        if (sonChecked && allChecked){
            $('#xuan').css('display','inline-block') // 显示选择excel导出数据
            $('#sou').css('display','none') // 隐藏部分或全部excel导出数据
        }else{
            $('#xuan').css('display','none')
            $('#sou').css('display','inline-block')
        }
        // console.log('你点击我了')
        // console.log('你是否被选中', this.checked)
        // console.log('下级的选框', $("input[name='id[]']").prop('checked'))
    });

    // 单选
    $("input[name='id[]']").bind('click', function () {
        var radioData =  $("input:checked[name='id[]']");
        // 选择数据的长度
        var len = radioData.serializeArray().length;
        if (len > 0) {
            $('#xuan').css('display','inline-block') // 显示选择excel导出数据
            $('#sou').css('display','none') // 隐藏部分或全部excel导出数据
        } else {
            $('#xuan').css('display','none')
            $('#sou').css('display','inline-block')
            $('#checkAlls').prop('checked',false); // 取消选择全选按钮
        }
        // console.log('你点击了单选')
        // console.log('点击的结果为：', this.checked)
        // console.log('你选择的数据是', radioData.serializeArray())
        // console.log('你选择的数据长度是',len)
    });

    function xuan() {
        var checkData = $("input:checked[name='id[]']");
        var dataArr = checkData.serializeArray();
        dataArr.push({name: 'search',value: 'all'})
        // console.log('选择的数据是', checkData.length)
        // console.log('选择的数据是', checkData.serializeArray())
        // console.log('选择的数组是', dataArr)
        $.ajax({
            type: 'post',
            url: '/admin/driver_settlement/get_excel',
            data: dataArr,
            success: function (res) {
                if (res.code == 5){
                    // console.log('data', res);
                    location.href = res.msg; // 下载文件
                    // 删除文件
                    unclinkFile(res.msg)
                    layer.msg('导出数据成功');
                } else {
                    layer_open('excel导出数据','/admin/pub/role/id/1')
                }
            }
        });
    }
    function driverInfo(id) {
        var url = '/admin/driver/details';
        if (!id){
            layer.msg('缺少必要的参数');
        }
        $.ajax({
            type: 'get',
            url: url,
            data:{ id: id },
            success: function (data) {
                if (data.code == 1){
                    layer.msg(data.msg)
                    return false
                }else{
                    layer_open('详细资料','/admin/driver/details/id/'+id,{w:'1300px',h:'750px'})
                }
            }
        })
    }
</script>
{/block}

